import Koa from "koa";
import Router from "@koa/router";
import koaBody from "koa-body"
import session from "koa-session";
import Cros from "@koa/cors"
import KoaLogger from "koa-logger";
import routes from "./routes/index.js";
const app = new Koa();

const CONFIG = {
    key: "koa:sess",
    maxAge: 86400000,
    overwrite: true,
    httpOnly: true,
    signed: true,
    rolling: false,
    renew: true,
};

const router = new Router();

app.use(session(CONFIG, app));
app.use(koaBody({
    multipart: false,
    encode: "utf-8"
}))
app.use(KoaLogger())

app.use(Cros({
    origin: function(ctx) {
        ctx.set('Access-Control-Allow-Origin', "*");
    }
}))

routes(router)

app.use(router.routes());
app.use(router.allowedMethods());


app.listen(8090, () => {
    console.log("Server started with 8090")
});